﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Citi.Scheduler.Domain;
using System;

namespace Citi.Scheduler.WebUi.Models
{
    public class RoutineModel : ModelBase<RoutineModel, Routine>
    {
        public string Name { get; set; }
        public int ResponsibleId { get; set; }
        [Display(Name = "Category")]
        public int CategoryId { get; set; }
        public int LibraryVersionId { get; set; }
        public string Class { get; set; }
        public int? PredecessorRoutineId { get; set; }
        public int? PreferredMachineId { get; set; }
        public bool UseLastVersion { get; set; }
        public int EstimatedTime { get; set; }
        public int PercentageAcceptableVariation { get; set; }
        public short TryAgainAfterMinutes { get; set; }
        public short TimesToTryAgain { get; set; }
        public TimeSpan CustomerSLA { get; set; }
        public int MinutesWarningSLA { get; set; }
        public int MinutesCriticalSLA { get; set; }

        [Display(Name = "Responsible")]
        public UserModel User { get; set; }
        public CategoryModel Category { get; set; }
        public LibraryVersionModel LibraryVersion { get; set; }
        public MachineModel PreferredMachine { get; set; }
        public RoutineModel PredecessorRoutine { get; set; }

        public IEnumerable<RoutineScheduleModel> RoutineSchedules { get; set; }
        public IEnumerable<RoutineParameterModel> RoutineParameters { get; set; }

        private int? predecessorLibraryId;
        public int? PredecessorLibraryId
        {
            get
            {
                return PredecessorRoutine != null ? PredecessorRoutine.LibraryId : predecessorLibraryId;
            }
            set
            {
                predecessorLibraryId = value;
            }
        }

        private int libraryId;
        public int LibraryId
        {
            get
            {
                return LibraryVersion != null ? LibraryVersion.LibraryId : libraryId;
            }
            set
            {
                libraryId = value;
            }
        }

        private int type;
        public int Type
        {
            get
            {
                return LibraryVersion != null ? (int)LibraryVersion.Type : type;
            }
            set
            {
                type = value;
            }
        }

        public bool Active { get; set; }
    }
}